<div class="modal-content">
  <div class="modal-header">
    <h6 class="modal-title text-purple">网络文件</h6>
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
  </div>
  <div class="modal-body py-4">
    <form class="w-100" id="markDownForm" action="{:DcUrl('markdown/attachment/save')}">
     {if function_exists('attachmentSave')}
     <div class="form-group">
      <label for="attachment_score"><strong>所需积分</strong></label>
      <input type="text" class="form-control form-control-sm" name="attachment_score" id="attachment_score" value="0" autocomplete="off" required>
      </div>
      <div class="form-group">
        <label for="attachment_url"><strong>外链地址</strong></label>
        <input type="url" class="form-control form-control-sm" name="attachment_url" id="attachment_url" autocomplete="off" required>
      </div>
      <div class="form-group text-center">
        <button class="btn btn-purple" type="submit">提交</button>
      </div>
      {else/}
      <div class="input-group input-group-sm">
        <div class="input-group-prepend">
          <span class="input-group-text">外链地址</span>
        </div>
        <input class="form-control" type="url" name="attachment_url" id="attachment_url" autocomplete="off" required>
        <div class="input-group-append">
          <button class="btn btn-secondary" type="submit" style="border-top-right-radius: .2rem;border-bottom-right-radius: .2rem;">提交</button>
        </div>
      </div>
      {/if}
    </form>
  </div>
</div>
<script>
$(function() {
    $(document).on('submit', '#markDownForm', function() {
        var self = $(this);
        daicuo.ajax.post($(this).attr('action'), $(this).serialize(), function($result, $status, $xhr) {
            if ($result.code == 1) {
                $('.dc-modal .modal-dialog').html(false);
                $('.dc-modal').modal('hide');
                if($result.data.score){
                   $.fn.markdown.element.replaceSelection("\n"+'['+$result.data.name+'（需要'+$result.data.score+'个积分）]('+$result.data.url+')');
                }else{
                   $.fn.markdown.element.replaceSelection("\n"+'['+$result.data.name+']('+$result.data.url+')');
                }
            }else{
                daicuo.bootstrap.dialog($result.msg);
            }
        });
        return false;
    });
});
</script>